<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
define("jianshu_Version", "1.6");

function is_pjax(){
    return array_key_exists('HTTP_X_PJAX', $_SERVER) && $_SERVER['HTTP_X_PJAX'];
}
function themeConfig($form) {
	echo '<p style="font-size:16px;text-align:center;">感谢您使用仿简书主题<font color="#4A89DC">变异版</font><font color="#F40"> '.jianshu_Version.'</font> !</p>';

	$logoText = new Typecho_Widget_Helper_Form_Element_Text('logoText', NULL, NULL, _t('网站文字LOGO'), _t('网站文字LOGO，单个文字;为空时取网站标题第一个文字'));
    $form->addInput($logoText);

	$avatarUrl = new Typecho_Widget_Helper_Form_Element_Text('avatarUrl', NULL, NULL, _t('博主头像'), _t('博主头像地址，为空则不显示'));
    $form->addInput($avatarUrl);
	
    $comment = new Typecho_Widget_Helper_Form_Element_Radio('comment',array('comments' => _t('默认评论框'),'comments_duoshuo' => _t('多说评论框')),'comments',_t('评论框选择'),_t("选择后首页、文章页评论数自动同步更改"));
    $form->addInput($comment);
	
    $duosuokey = new Typecho_Widget_Helper_Form_Element_Text('duosuokey', NULL, 'DUOSHUO_KEY', _t('<font color="#F40">多说评论框Key</font>'), _t('请前往<a href="http://duoshuo.com/">http://duoshuo.com/</a>获取Key(既多说评论框域名)<br/>获取步骤为：</p>登录多说->后台管理->工具->获取代码->short_name:<font color="#F40">你的站点key</font>'));
    $form->addInput($duosuokey);
	
    $duosuojs = new Typecho_Widget_Helper_Form_Element_Text('duosuojs', NULL, '//static.duoshuo.com/embed.js', _t('多说评论框JS'), _t('多说评论框embed.js路径，可用于embed.js本地化使用'));
    $form->addInput($duosuojs);
	
    $Show = new Typecho_Widget_Helper_Form_Element_Checkbox('Show', array('favatar' => _t('文章底部头像'),'tags' => _t('文章底部标签'),'author' => _t('文章发布信息'),'footer' => _t('全站底部分类')),array('favatar',  'tags',  'footer' , 'author'), _t('自定义显示'));
    $form->addInput($Show->multiMode());

    $PageShow = new Typecho_Widget_Helper_Form_Element_Checkbox('PageShow', array('pfavatar' => _t('底部头像'),'ptags' => _t('底部标签'),'ptool' => _t('点赞捐助')),array('ptool'), _t('独立页面显示'));
    $form->addInput($PageShow->multiMode());
	
    $menu = new Typecho_Widget_Helper_Form_Element_Radio('menu', array('cat' => _t('分类目录'),'page' => _t('独立页面')),'page',_t('导航栏输出'));
    $form->addInput($menu);    

	$post_author = new Typecho_Widget_Helper_Form_Element_Radio('post_author',array('1' => _t('图片地址'),'2' => _t('邮箱地址'),'3' => _t('不显示头像')),'2',_t('文章作者头像'),_t("图片地址使用博主头像</br>邮箱地址使用作者邮箱设置的gravatar头像"));
    $form->addInput($post_author);
	
	$tips = new Typecho_Widget_Helper_Form_Element_Text('tips', NULL, NULL, _t('底部头像描述'), _t('底部头像文字签名描述'));
    $form->addInput($tips);
	
    $icpNum = new Typecho_Widget_Helper_Form_Element_Text('icpNum', NULL, NULL, _t('网站备案号'), _t('在这里填入网站备案号'));
    $form->addInput($icpNum);
    
    $siteStat = new Typecho_Widget_Helper_Form_Element_Textarea('siteStat', NULL, NULL, _t('统计代码'), _t('在这里填入网站统计代码'));
    $form->addInput($siteStat);
    
    $bgPhoto = new Typecho_Widget_Helper_Form_Element_Text('bgPhoto', NULL, NULL, _t('网站背景图'), _t('在这里填入背景图网址'));
    $form->addInput($bgPhoto);
    
	$iconCss = new Typecho_Widget_Helper_Form_Element_Textarea('iconCss', NULL, NULL, _t('图标样式'), _t('在这里填入图标样式代码'));
    $form->addInput($iconCss);
	
    $listStyle = new Typecho_Widget_Helper_Form_Element_Checkbox('listStyle',array('excerpt' => _t('显示摘要'),'more' => _t('全文输出'),'thumb' => _t('显示缩略图')),array('excerpt', 'thumb'), _t('列表显示'),_t("全文输出如有分隔符“--more--”则将显示阅读更多"));
	$form->addInput($listStyle);
}

function getReadMode($icon=false){
	$class = Typecho_Cookie::get('read-mode','day');
	if($icon){
		$class = $class == 'day' ? 'fa fa-sun-o' : 'fa fa-moon-o';
	}else{
		$class = 'day' == $class ? '' : 'night-mode';
	}
		
	echo $class;
}

/**
 * 重写评论显示函数
 */
function threadedComments($comments, $options){
    $commentClass = '';
    if ($comments->authorId) {
        if ($comments->authorId == $comments->ownerId) {
            $commentClass .= ' comment-by-author';
        } else {
            $commentClass .= ' comment-by-user';
        }
    }

    $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent';
    ?>
<li itemscope itemtype="http://schema.org/UserComments" id="<?php $comments->theId(); ?>" class="comment-body<?php
    if ($comments->levels > 0) {
        echo ' comment-child';
        $comments->levelsAlt(' comment-level-odd', ' comment-level-even');
    } else {
        echo ' comment-parent';
    }
    $comments->alt(' comment-odd', ' comment-even');
    echo $commentClass;
?>">
    <div class="comment-avatar">
		<img class="avatar" src="<?php echo Tools_Plugin::gravatarUrl($comments->mail, $options->avatarSize, null,$options->defaultAvatar);?>" width="<?php echo $options->avatarSize;?>">
	</div>
    <div class="comment-meta">
        <div class="comment-meta-author"><?php $comments->author();?></div>
        <div class="comment-meta-time">
        <a href="<?php $comments->permalink(); ?>"><time itemprop="commentTime" datetime="<?php $comments->date('c'); ?>"><?php $options->beforeDate();
        $comments->date($options->dateFormat);
        $options->afterDate(); ?></time></a>
        </div>
        <?php if ('waiting' == $comments->status) { ?>
        <em class="comment-awaiting-moderation"><?php $options->commentStatus(); ?></em>
        <?php } ?>
        <div class="comment-meta-reply">
            <?php $comments->reply($options->replyWord); ?>
        </div>
    </div>
    <div class="comment-content" itemprop="commentText">
    <?php $comments->content(); ?>
    </div>
    
    <?php if ($comments->children) { ?>
    <div class="comment-children" itemprop="discusses">
        <?php $comments->threadedComments(); ?>
    </div>
    <?php } ?>
</li>
<?php
}